package pw.caffe.common;

import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.List;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import pw.caffe.common.net.NEXRequest;
import pw.caffe.common.net.NEXResponse;

public abstract class IAction {

    protected IoSession ioSession = null;

    public abstract void perform(NEXRequest Request, List<NEXResponse> responseList);

    public List<NEXResponse> handleNEXRequest(NEXRequest Request)
    {
        List<NEXResponse> responseList = new ArrayList<NEXResponse>();

        this.perform(Request, responseList);
        return responseList;
    }

    protected IoBuffer generateIoBuffer()
    {
        IoBuffer ioBuffer = IoBuffer.allocate(100).setAutoExpand(true);
        ioBuffer.order(ByteOrder.LITTLE_ENDIAN);
        ioBuffer.putInt(0);
        ioBuffer.putInt(0);
        return ioBuffer;
    }

    public IoSession getIoSession()
    {
        return ioSession;
    }

    public void setIoSession(IoSession ioSession)
    {
        this.ioSession = ioSession;
    }

    /*
     * 自定义方法，可以和缓存一块儿使用
     */
    public void initSession()
    {
        this.ioSession.removeAttribute("playerId");
    }
}
